wd='/home/jc148322/scripts/test.sh/';dir.create(wd); setwd(wd)

for(i in 1:30) { cat(i,'\n')
	zz=file(paste('test',i,'.sh',sep=''),'w')
		cat('#!/bin/bash\n',file=zz)
				
				 cat("R CMD BATCH --no-save --no-restore '--args i=\"",i,"\" wd=\"",wd,"\" ' ~/scripts/test.r ",i,'.test.Rout \n',sep='',file=zz) #run the R script in the background
				 
			close(zz)


}